package com.browner.game;

import java.util.*;

public class Main {

	private static Scanner in = new Scanner(System.in);
	private static Player player;
	private static boolean cheat = false;

	public static void main(String[] args) throws Exception{
		boolean dead = false;
		System.out.println("Welcome to Game v0.3 alpha!");
		System.out.print("Please enter your name: ");
		String name = in.nextLine();
		if(name.equals("Jade Harley") || name.equals("John Egbert") || name.equals("Dave Strider") || name.equals("Rose Lalonde") || name.equals("Jake English") || name.equals("Calliope") || name.equals("Caliborn")) {
			player = new Player(name, 100);
			System.out.println("Hello, fellow Homestuck reader. Here's 80 extra health!");
		}
		else if(name.equalsIgnoreCase("uuddlrlrbaba") || name.equalsIgnoreCase("up up down down l r l r b a b a")  || name.equalsIgnoreCase("up up down down left right left right b a b a") || name.equalsIgnoreCase("u u d d l r l r b a b a") || name.equalsIgnoreCase("u u d d left right left right b a b a") || name.equalsIgnoreCase("up, up, down, down, l, r, l, r, b, a, b, a") || name.equalsIgnoreCase("u, u, d, d, l, r, l, r, b, a, b, a")) {
			System.out.println("Konami Code entered. Cheats enabled.");
			try{Thread.sleep(2000);}catch(Exception e){return;}
			cheat = true;
			System.out.println("Since we both know your name isn't the Konami Code, would you kindly enter your real name? ");
			name = in.nextLine();
			player = new Player(name, 20);
		}
		else player = new Player(name, 20);
		System.out.println("You have "+player.getMaxHealth()+" health.");
		Thread.sleep(2000);
		System.out.println("Endless mode is enabled. To disable, code another mode.");
		for(int level = 1; !dead; level++) {
			for(int i = 1; i <= 5; i++) {
				Monster monster = new Monster(level);
				System.out.println("A level "+monster.getLevel()+" monster appeared!");
				System.out.println("It has "+monster.getHealth()+" health.");
				Thread.sleep(2000);
				boolean monsterDead = false;
				//beginning of combat loop
				while(!monsterDead) {
					boolean done = false;
					while(!done) {
						done = true;
						System.out.println("What would you like to do? (attack/heal/flee):");
						String choice = in.next();
						if(choice.equalsIgnoreCase("attack")) {
							monsterDead = monster.damage(player.attack(monster.getDefense()));
						}
						else if(choice.equalsIgnoreCase("heal"))
							player.heal();
						else if(choice.equalsIgnoreCase("flee"))
							System.out.println("This is endless mode, stupid! If you flee, you will just have to fight another monster!");
						else if(choice.equalsIgnoreCase("throw lemon")) {
							System.out.println("You threw an explosive lemon. It killed your enemy in one hit.");
							monsterDead = monster.damage(monster.getHealth());
						}
						else {
							System.out.println("Please enter a valid option.");
							done = false;
						}
					}
					//end of player section
					try{Thread.sleep(2000);}catch(Exception e){return;}
					if(!monsterDead) {
						//monster attack
					}
					else {
						System.out.println("You defeated your enemy!");
						try{Thread.sleep(1000);}catch(Exception e){return;}
					}
				}
				//end of combat loop
			}
			//at this point, the player has fought 5 monsters and deserves a level up
			player.levelUp();
		}
		//if code reaches this point, player has died
		System.out.println("You have lost. Please place your keyboard on the ground next to you and assume the party escort submission position.");
		try{Thread.sleep(2000);}catch(Exception e){return;}
		loseGame();
	}
	
	//deprecated
	public static void loseGame() throws YouLostTheGameException {
		throw new YouLostTheGameException("You lost the game.");
	}
}
